package com.kaifamiao.N0809;

import java.util.Arrays;

public class Node2 {
    public static void main(String[] args) {
        // 自动装箱
        Integer num = Integer.valueOf(1);
        Integer num1 = 2;

        // 值是否相等, == , equals
        // 比较大小, compare / compareTo   0  >0  <0

        Integer[] nums = new Integer[]{6, 2, 9, 1, 3, 4};
        // 排序
        Arrays.sort(nums);

        System.out.println(Arrays.toString(nums));

        /**
         *  自然顺序, 实现 java.lang.Comparable 接口  compareTo 自然比较方法
         */
        Person p = new Person();
        p.setName("沸羊羊");
        p.setAge(8);

        Person p1 = new Person();
        p1.setName("双面龟");
        p1.setAge(10);

        Person p2 = new Person();
        p2.setName("黑小虎");
        p2.setAge(12);

        Person p3 = new Person();
        p3.setName("梁全年");
        p3.setAge(10);

        Person[] persons = {p, p1, p2, p3};

        sort(persons);

        System.out.println(Arrays.toString(persons));
    }

    public static void sort(Person[] persons) {

        for (int i = 0; i < persons.length - 1; i++) {

            for (int j = 0; j < persons.length - 1 - i; j ++){
                if (persons[j].compareTo(persons[j + 1]) > 0){
                    Person p = persons[j];
                    persons[j] = persons[j + 1];
                    persons[j + 1] = p;
                }
            }
        }
    }
}
